<?php
/**
 * Created by PhpStorm.
 * User: DELL
 * Date: 2021/3/5
 * Time: 11:57
 */

namespace App\Api\V1\Models;
use Illuminate\Database\Eloquent\Model;

class GoodsCategory extends Model
{
    protected $table = 'goods_category';
    public $timestamps = false;
    //商品分类添加
    public function addCategoryItem(){
        $data =[
            'parent_id'=>'0',
            'name'=>'杜鸿波',
            'name_phonetic'=>'123',
            'alias'=>'1805',
            'alias_phonetic'=>'d',
            'category_pic'=>'',
            'category_ico'=>'',
            'keywords'=>'',
            'description'=>'',
            'category_type'=>'0',
            'sort'=>'1',
            'is_navi'=>'0',
            'status'=>'1',
        ];
        $this->parent_id = $data['parent_id'];
        $this->name = $data['name'];
        $this->name_phonetic = $data['name_phonetic'];
        $this->alias = $data['alias'];
        $this->alias_phonetic = $data['alias_phonetic'];
        $this->category_pic = $data['category_pic'];
        $this->category_ico = $data['category_ico'];
        $this->keywords = $data['keywords'];
        $this->description = $data['description'];
        $this->category_type = $data['category_type'];
        $this->sort = $data['sort'];
        $this->is_navi = $data['is_navi'];
        $this->status = $data['status'];
        if ($this->save()){
            return $this->toArray();
        }
        return false;
    }
    //商品分类修改
    public function setCategoryItem(){
        $data =[
            'parent_id'=>'0',
            'name'=>'杜鸿波1',
            'name_phonetic'=>'123',
            'alias'=>'1805',
            'alias_phonetic'=>'d',
            'category_pic'=>'',
            'category_ico'=>'',
            'keywords'=>'',
            'description'=>'',
            'category_type'=>'0',
            'sort'=>'1',
            'is_navi'=>'0',
            'status'=>'1',
        ];
        $res = GoodsCategory::where('goods_category_id',847)->update($data);
        if($res){
            return $this->toArray();
        }
        return false;
    }
    //获取商品分类列表
    public function getCategoryList(){
        return $this->get()->toArray();
    }
    //删除商品分类
    public function delCategoryItem(){
        $res = GoodsCategory::where('goods_category_id',847)->delete();
        if($res){
            return $this->toArray();
        }
        return false;
    }
}